//
//  BaseHttpTool.m
//
//  Created by Northwan on 15/4/14.
//  Copyright (c) 2015年  All rights reserved.
//

#import "BaseHttpTool.h"


@implementation BaseHttpTool
+ (void)get:(NSString *)url params:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    NSLog(@"geturl=%@",url);
    NSLog(@"params=%@",params);
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    // 2.发送GET请求
    [mgr GET:url parameters:params
     success:^(AFHTTPRequestOperation *operation, id responseObj) {
         if (success) {
             success(operation.responseData);
         }
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         if (failure) {
             failure(error);
         }
     }];
}

+ (void)post:(NSString *)url params:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    NSLog(@"url=%@",url);
    NSLog(@"params=%@",params);
    
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    // 2.发送POST请求
    [mgr POST:url parameters:params
      success:^(AFHTTPRequestOperation *operation, id responseObj) {
          if (success) {
              success(operation.responseData);
          }
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog ( @"failure:%@" , error );
          if (failure) {
              failure(error);
          }
      }];
}

@end
